<template>
  <el-table :data="get_roleList" border style="width: 100%">
    <el-table-column prop="id" label="角色编号" width="100"></el-table-column>
    <el-table-column prop="rolename" label="角色名称" width="180"></el-table-column>
    <el-table-column prop="status" label="状态">
      <template v-slot="item">
        <el-button type="primary" plain size="small" v-if="item.row.status == 1">启用</el-button>
        <el-button type="danger" plain size="small" v-else>禁用</el-button>
      </template>
    </el-table-column>
    <el-table-column  label="操作">
      <template v-slot="item">
        <el-button type="primary" size="small" @click="edit(item.row.id)">编辑</el-button>
        <el-button type="danger" size="small" @click="delItem(item.row.id)">删除</el-button>
      </template>
    </el-table-column>
  </el-table>
</template>

<script>
import { mapGetters,mapActions } from 'vuex'; 
import {roledelete} from "@/request/api.js"
export default {
  data() {
    return {
      
    };
  },
  computed:{
    ...mapGetters({
      get_roleList:"role/get_roleList"
    })
  },
  methods:{
    ...mapActions({
      action_roleList:"role/action_roleList",  //获取角色列表的方法
    }),
    //删除方法
    delItem(id){
      this.$confirm('是否删除该角色', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(async () => {
          try{
            let res = await roledelete({id});
            if(res.code == 200){
              //提示，更新数据（重新请求数据）
              this.$message.success(res.msg); 
              this.action_roleList();
            }else{
              this.$message.info(res.msg); 
            }
          }catch(err){
            this.$message.error(err); 
          }


        }).catch(() => {
          this.$message.info('已取消删除');          
        });
    },
    //点击编辑
    edit(id){
      //通知父组件显示弹框，弹框里面要有对应的内容  id
      this.$emit("edit",id)
    }
  },
  //组件一挂载完成，请求数据，渲染列表
  mounted(){
     this.action_roleList();
  }
};
</script>

<style>
</style>